﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DelonixRegiaHotel.Classes;
using DelonixRegiaHotel.DBManager;

namespace DelonixRegiaHotel
{
    public partial class DeleteCustomer : Form
    {
        string passCustomerID;
        public DeleteCustomer()
        {
            InitializeComponent();
            ArrayList getCustomerInfo = ManageCustomerDBManager.GetAllCustomerDetails();
            cboxnric.Items.Add("-Select Nric-");
            foreach (Customer c in getCustomerInfo)
            {
                cboxnric.Items.Add(c.Nric + ", " + c.CustomerID);
            }
            cboxnric.SelectedIndex = 0;
        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void cboxnric_SelectedIndexChanged(object sender, EventArgs e)
        {
            ArrayList getCustomerInfo = ManageCustomerDBManager.GetAllCustomerDetails();
            foreach (Customer c in getCustomerInfo)
            {
                if (cboxnric.SelectedItem.ToString().Contains(c.CustomerID) && cboxnric.SelectedItem.ToString().Contains(c.Nric))
                {
                    lblshowcustomerid.Text = c.CustomerID;
                    lblshowfirstname.Text = c.FirstName;
                    lblshowlastname.Text = c.LastName;
                    lblshowhomeaddress.Text = c.HomeAddress;
                    lblshowpostalcode.Text = Convert.ToString(c.PostalCode);
                    lblshowcountry.Text = c.Country;
                    lblshowdob.Text = Convert.ToString(c.Dob.ToShortDateString());
                    lblshowcontactno.Text= Convert.ToString(c.ContactNo);
                    lblshowemail.Text = c.Email;
                    lblshownric.Text = c.Nric;
                    passCustomerID = c.CustomerID;
                }
            }
        }

        private void btndelete_Click(object sender, EventArgs e)
        {
            if(ManageCustomerDBManager.TestWhetherCustomerIDExistsInCheckIn(passCustomerID) == true)
            {
                MessageBox.Show("Customer ID found assiocated with one of the booking information, please delete the booking first in order to delete this customer");
                return;
            }

            if(ManageCustomerDBManager.DeleteCustomerInformationByCustomerID(passCustomerID) == 1)
            {
                MessageBox.Show("Delete was successful");
                this.Hide();
            }
        }



    }
}
